![]() |
PATH![]() |
![]() ![]() |
To examine a definition of an object class, a command, or some other word supported by an application, you can open that application's dictionary from the Script Editor. A dictionary is a set of definitions for words that are understood by a particular application. Unlike other scripting languages, AppleScript does not have a single fixed set of definitions for use with all applications. Instead, when you write scripts in AppleScript, you use both definitions provided by AppleScript and definitions provided by individual applications to suit their capabilities.
Dictionaries tell you which objects are available in a particular application and which commands you can use to control them. You can view an application's dictionary by dropping the application's icon on the Script Editor's icon, or by opening the application with the Script Editor's Open Dictionary command. Figure 2-6 shows the Finder's dictionary, with the Item class displayed. For more information on using the Script Editor, refer to the AppleScript section of the Mac OS Help Center.
To use the words from an application's dictionary in a script, you must indicate which application you want to manipulate. You can do this with a Tell statement that lists the name of the application:
tell application "Finder"
clean up the front window
end tell
Figure 2-6 The Finder's dictionary, with Item class displayed
When it encounters a Tell statement, AppleScript reads the words in the specified application's dictionary and uses them to interpret the statements in the Tell block. For example, AppleScript uses the words in the Finder dictionary to interpret the Clean Up command in the previous script sample.
When you use a Tell statement or specify an application name completely in a statement, the AppleScript extension gets the dictionary resource for the application and reads its dictionary of commands, objects, and other words. Every scriptable application has a dictionary resource (of resource type 'aete' ) that defines the commands, objects, and other words script writers can use in scripts to control the application. Figure 2-7 shows how AppleScript gets the words in the Finder's dictionary.
Figure 2-7 How the Script Editor accesses the Finder's dictionary
In addition to the terms defined in application dictionaries, AppleScript includes its own standard terms. Unlike the terms in application dictionaries, the standard AppleScript terms are always available. You can use these terms (such as If, Tell, and First) anywhere in a script. This guide describes the standard terms provided by AppleScript.
The words in system and application dictionaries are known as reserved words. When defining new words for your script--such as identifiers for variables--you cannot use reserved words.